<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Slide_Option_Schedule_Module
 * @category   Model
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */
class Slide_Option_Impression_Module implements Slide_Option_Interface
{
    public function getTitle()
    {
        return 'Impressions';
    }
    
    public function getData($slideId)
    {
    	return;
    }
    
    public function saveData($slideId, array $data)
    {
    	return;
    }
    
    public function getOptionForm($slideId)
    {
        $impression = new Slide_Option_Impression_Data();
        
        $data = $impression->find($slideId);
        if (is_null($data)) {
            $data = array(
                'slideId' => $slideId,
            );
        } else {
            $data = $data->toArray();
        }
        
        return $impression->form($data)->__toString();
    }
    
    public function saveOptionForm($slideId, Array $data)
    {
        $impression = new Slide_Option_Impression_Data();
        
        $form = $impression->form(array('slideId' => $slideId));
        
        if ($form->isValid($data)) {
            $existingData = $impression->find($slideId);

            if (is_null($existingData)) {
                $impression->insert($data);
            } else {
                $data['slideId'] = $slideId;
                $impression->update($data, null);
            }
        }
        
        return $form->getErrorMessages();
    }
}